package 剑指offer;

import java.util.Stack;

public class _31栈的压入弹出序列 {
	/**
	 * 
	 *@time 2021年2月18日下午5:56:08
	 * 
	 *@param pushed
	 *@param popped
	 *@return boolean
	 *
	 *@see
	 */
    public boolean validateStackSequences(int[] pushed, int[] popped) {
    	Stack<Integer> stack=new Stack<Integer>();
    	int index=0;
    	for (int item : pushed) {
			stack.push(item);
			while(!stack.isEmpty()&&stack.peek()==popped[index]) {
				stack.pop();
				index++;
			}
		}
    	return stack.isEmpty();
    }
}
